package ar.edu.unlu.sistemas.movirdroid.business.strategy;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import ar.edu.unlu.sistemas.movirdroid.business.util.Params;
import ar.edu.unlu.sistemas.movirdroid.business.util.QueryResultComparator;
import ar.edu.unlu.sistemas.ws.business.QueryResultVO;

public abstract class ProcessQueryStrategy {

	public abstract Collection<QueryResultVO> execute(String query);

	protected List<QueryResultVO> filterResults(List<QueryResultVO> queryResults) {
		
		List<QueryResultVO> outResults = new LinkedList<QueryResultVO>();
		//Ordenamos los resultados con un umbral flotante
		Collections.sort((List<QueryResultVO>)queryResults, new QueryResultComparator());
		if (!queryResults.isEmpty()) {
			Float ac1 = new Float(0);
			int i = 1;
			for (QueryResultVO qrTempVO : queryResults) {
				if (qrTempVO.getValue() > Params.THRESHOLD*ac1 && i <= Params.RESULTS_LIMIT) {
					outResults.add(qrTempVO);
					ac1 = (Float) qrTempVO.getValue();
					i++;
				} else break;
					
			}
		}
		return outResults;
	}
}
